// TypeScript file

class MoreUI extends eui.Component {

    private closeBtn: eui.Button;
    private additionalTop: eui.ToggleButton;
    private additional: eui.Image;
    private paytop: eui.ToggleButton;
    private pay: eui.Scroller;
    private paylineTop: eui.ToggleButton;
    private playline: eui.Image;
    private settop: eui.ToggleButton;
    private setting: eui.Group;
    private bettop: eui.ToggleButton;
    private bet: eui.Group;
    private tophash;
    private contexthash;
    private curTopKey: string = "5";
    private curContentKey: string = "5";
    private setUI:Setting;

    private autoSetting:AutoRotationSetting;


    public context: MainPanel
    private bg: Bg = null;

    public constructor(context: MainPanel) {
        super();
        this.skinName = "moreUI";
        this.addEventListener(egret.Event.ADDED_TO_STAGE, this.onAddToStage, this);
        this.addEventListener(egret.Event.REMOVED_FROM_STAGE, this.onRemoveFromStage, this);
        this.context = context;

    }

    private onAddToStage(event: egret.Event) {
        if (this.bg != null) this.removeChild(this.bg.icon);
        this.bg = new Bg(this, 'mask_in_png');
        this.bg.setIcon(this.width, this.height, 0)

        this.tophash = {
            "1": this.additionalTop,
            "2": this.paylineTop,
            "3": this.paytop,
            "4": this.settop,
            "5": this.bettop
        };
        this.contexthash = {
            "1": this.additional,
            "2": this.playline,
            "3": this.pay,
            "4": this.setting,
            "5": this.bet
        };

        this.closeBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onCloseEvent, this);
        this.initTop(true);
        this.initContent();
        this.tophash[this.curTopKey].selected = false;
        this.contexthash[this.curContentKey].$setVisible(true);

        //设置面板初始化
        this.setUI = new Setting(this.context,this.setting);

        //多次旋转设置
        this.autoSetting = new AutoRotationSetting(this.context,this.bet,this);
    }

    private onRemoveFromStage(event: egret.Event):void
    {
        this.setUI.onRemove();
    }

    private initTop(isInit: boolean) {
        for (var top in this.tophash) {
            this.tophash[top].selected=true;
            if (isInit) this.tophash[top].addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTopEvent, this);
        }
    }

    private initContent() {
        for (var context in this.contexthash) {
            this.contexthash[context].$setVisible(false);
        }
    }

    private onCloseEvent(event: egret.Event) {
        // this.context.removeChild(this);
        this.$setVisible(false);
        this.context.soundctr.playSound("click_mp3");
    }


    private onTopEvent(event: egret.Event) {
        this.initTop(false)
        this.initContent();
        var name = event.target.name;
        this.tophash[name].selected=false;
        this.contexthash[name].$setVisible(true);

    }

    public setBetShow():void
    {
         this.initTop(false)
         this.initContent();
         this.curTopKey = "5";
         this.curContentKey = "5";
         this.tophash[this.curTopKey].selected=false;
         this.contexthash[this.curContentKey].$setVisible(true);
    }

    public setAutoSetTouchEvent(enable:boolean,isAuto:boolean):void
    {
        this.autoSetting.setTouchEvent(enable,isAuto);
    }

    public setAutoStopNum(num:number)
    {
        this.autoSetting.setAutoBtnNum(num);
    }

}